package org.UserHouse.Dao.Imp;

import org.UserHouse.Dao.TypeDao;
import org.UserHouse.Utils.Dbutils;
import org.UserHouse.entity.Type;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author bin
 * @date 2024-12-16
 */
public class TypeDaoImp implements TypeDao {
    @Override
    public List<Type> SelectType() {
        List<Type> list = new ArrayList<>();
        String sql = "select t_id, t_name, t_parent_id from t_type";
        Connection conn = Dbutils.getConnection();
        ResultSet rst = null;
        PreparedStatement pst = null;
        try {
            pst = conn.prepareStatement(sql);
            rst = pst.executeQuery();
            while (rst.next()) {
                Type t = new Type();
                int Tid = rst.getInt(1);
                String Tname = rst.getString(2);
                int TparentId = rst.getInt(3);

                t.setTid(Tid);
                t.setTname(Tname);
                t.setTparentId(TparentId);

                list.add(t);
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return list;
    }

    @Override
    public Type SelectType(int tid) {
        return null;
    }

    @Override
    public int AddType(Type type) {
        return 0;
    }

    @Override
    public int DeleteType(int Tid) {
        return 0;
    }

    @Override
    public int UpdateType(Type type) {
        return 0;
    }
}
